<?php


namespace api\modules\v1\controllers\system\base;

use common\helpers\CommonHelper;
use Yii;
use api\controllers\OnAuthController;
use common\models\base\Profession;

class ProfessionController extends OnAuthController
{
    public $modelClass = Profession::class;

   // protected $optional = ['index-profession', 'update-profession', 'create-profession', 'view-profession', 'delete-profession','change-status-profession'];
    protected $optional = [];
    /**
     * v1/system/base/project/index-profession
     * $page
     * $pageSize
     *
     * @return mixed|\yii\db\ActiveRecord
     */
    public function actionIndexProfession()
    {
        $params = Yii::$app->request->get();
        $page = $params['page'] ?? 1;
        $pageSize = $params['pageSize'] ?? 15;

        return Yii::$app->services->profession->proList($page,$pageSize);
    }

    /**
     * v1/system/base/profession/create-profession
     * $name 岗位名称
     * $status  1 = 正常  0 = 失效
     *
     * @return mixed|\yii\db\ActiveRecord
     */
    public function actionCreateProfession()
    {
        $params = Yii::$app->request->post();
        $data = Yii::$app->services->profession->proCreate($params);

        return  CommonHelper::api($data['code'],$data['message']);
    }

    /**
     * v1/system/base/profession/proUpdate-profession
     * $name 岗位名称
     * $status  1 = 正常  0 = 失效
     *
     * @return mixed|\yii\db\ActiveRecord
     */
    public function actionUpdateProfession()
    {
        $params = Yii::$app->request->post();
        $data = Yii::$app->services->profession->proUpdate($params,$params['id']);

        return  CommonHelper::api($data['code'],$data['message']);
    }

    /**
     * v1/system/base/profession/change-status-Profession
     * $id
     * $status  1 = 正常  0 = 失效
     *
     * @return mixed|\yii\db\ActiveRecord
     * @throws \Exception
     */
    public function actionChangeStatusProfession()
    {
        $params = Yii::$app->request->post();
        $status = $params['status'];
        $id = $params['id'];

        return Yii::$app->services->profession->changeStatus($id,$status);
    }

    /**
     * v1/system/base/profession/delete-Profession
     * $id
     * $status  1 = 正常  0 = 失效
     *
     * @return mixed|\yii\db\ActiveRecord
     * @throws \Exception
     */
    public function actionDeleteProfession()
    {
        $id = Yii::$app->request->post('id');

        return Yii::$app->services->profession->deletes($id);
    }

}